package com.ete.lib.upload.logZip

import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ThreadUtils
import com.ete.lib.upload.UploadConstant
import com.ete.lib.upload.UploadManager
import net.lingala.zip4j.progress.ProgressMonitor

/**
 * Author:LiXian
 * <p>
 * Desc:TODO
 * Version:1.0
 * date 2024/1/8 14:53
 */
class ZipProgress(var fromZipPath: String, var toZipPath: String, var mCallback: IZipCallback) : ProgressMonitor() {

    override fun updateWorkCompleted(workCompleted: Long) {
        super.updateWorkCompleted(workCompleted)
        LogUtils.d(UploadManager.TAG, "压损进度percentDone：$percentDone")
        ThreadUtils.runOnUiThread {
            mCallback.onProgress(percentDone)
        }
    }

    override fun endProgressMonitorSuccess() {
        super.endProgressMonitorSuccess()
        ThreadUtils.runOnUiThread {
            mCallback.onSuccess(fromZipPath, toZipPath)
        }
    }

    override fun endProgressMonitorError(e: Throwable?) {
        super.endProgressMonitorError(e)
        ThreadUtils.runOnUiThread {
            mCallback.onError(UploadConstant.ERROR_ZIP_EXCEPTION, e?.message ?: "压缩异常")
        }
    }
}